<?php 
class indexAction extends sfAction{
	public function execute($request){
		$data['contact'] = SysPages::getContent(SYSPAGE_KEYS::CONTACT);
		$data['form'] = $request->getParameter('Contact', array());
		
		$form = new ContactForm();
		
		if ((count($data['form']) && $request->isMethod('POST'))){
			$error = '0';
			if($this->getUser()->getFlash('captcha', '--')== md5($data['form']['captcha']) && !empty($data['form']['captcha'])){
				
				$form->bind($data['form']);
				if($form->isValid()){
					if(ContactsTable::insert($data['form'])){
						
					}else{
						$error = '3';
					}
				}else{
					
					$error = '4';
				}
			}else{
				
				$error = '1';
			}
			$arr = array(
					'code' => $error,
					'message' => __('contact-error-'.$error));
			print_r(json_encode($arr));
			return sfView::NONE;
			//$this->setTemplate('error');
		}
		$this->setVar('data', $data);
		$this->setVar('form', $form);
	}
}